home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / uucp-104.lha / uucp-1.04 / util.c < prev    next >
C/C++ Source or Header  |  1993-02-13  |  4KB  |  145 lines

  1. /* util.c
  2.    A couple of UUCP utility functions.
  3.  
  4.    Copyright (C) 1991, 1992 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #if USE_RCS_ID
  29. const char util_rcsid[] = "$Id: util.c,v 1.2 1992/07/26 03:53:00 ian Rel $";
  30. #endif
  31.  
  32. #include <ctype.h>
  33.  
  34. #include "uudefs.h"
  35. #include "uuconf.h"
  36. #include "system.h"
  37.  
  38. /* Get information for an unknown system.  This will leave the name
  39.    allocated on the heap.  We could fix this by breaking the
  40.    abstraction and adding the name to qsys->palloc.  It makes sure the
  41.    name is not too long, but takes no other useful action.  */
  42.  
  43. boolean
  44. funknown_system (puuconf, zsystem, qsys)
  45.      pointer puuconf;
  46.      const char *zsystem;
  47.      struct uuconf_system *qsys;
  48. {
  49.   char *z;
  50.   int iuuconf;
  51.  
  52.   if (strlen (zsystem) <= cSysdep_max_name_len)
  53.     z = zbufcpy (zsystem);
  54.   else
  55.     {
  56.       char **pznames, **pz;
  57.       boolean ffound;
  58.  
  59.       z = zbufalc (cSysdep_max_name_len + 1);
  60.       memcpy (z, zsystem, cSysdep_max_name_len);
  61.       z[cSysdep_max_name_len] = '\0';
  62.  
  63.       iuuconf = uuconf_system_names (puuconf, &pznames, TRUE);
  64.       if (iuuconf != UUCONF_SUCCESS)
  65.     ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
  66.  
  67.       ffound = FALSE;
  68.       for (pz = pznames; *pz != NULL; pz++)
  69.     {
  70.       if (strcmp (*pz, z) == 0)
  71.         ffound = TRUE;
  72.       xfree ((pointer) *pz);
  73.     }
  74.       xfree ((pointer) pznames);
  75.  
  76.       if (ffound)
  77.     {
  78.       ubuffree (z);
  79.       return FALSE;
  80.     }
  81.     }
  82.  
  83.   iuuconf = uuconf_system_unknown (puuconf, qsys);
  84.   if (iuuconf == UUCONF_NOT_FOUND)
  85.     {
  86.       ubuffree (z);
  87.       return FALSE;
  88.     }
  89.   else if (iuuconf != UUCONF_SUCCESS)
  90.     ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
  91.  
  92.   for (; qsys != NULL; qsys = qsys->uuconf_qalternate)
  93.     qsys->uuconf_zname = z;
  94.  
  95.   return TRUE;
  96. }
  97.  
  98. /* See whether a file is in a directory list, and make sure the user
  99.    has appropriate access.  */
  100.  
  101. boolean
  102. fin_directory_list (zfile, pzdirs, zpubdir, fcheck, freadable, zuser)
  103.      const char *zfile;
  104.      char **pzdirs;
  105.      const char *zpubdir;
  106.      boolean fcheck;
  107.      boolean freadable;
  108.      const char *zuser;
  109. {
  110.   boolean fmatch;
  111.   char **pz;
  112.  
  113.   fmatch = FALSE;
  114.  
  115.   for (pz = pzdirs; *pz != NULL; pz++)
  116.     {
  117.       char *zuse;
  118.  
  119.       if (pz[0][0] == '!')
  120.     {
  121.       zuse = zsysdep_local_file (*pz + 1, zpubdir);
  122.       if (zuse == NULL)
  123.         return FALSE;
  124.  
  125.       if (fsysdep_in_directory (zfile, zuse, FALSE,
  126.                     FALSE, (const char *) NULL))
  127.         fmatch = FALSE;
  128.     }
  129.       else
  130.     {
  131.       zuse = zsysdep_local_file (*pz, zpubdir);
  132.       if (zuse == NULL)
  133.         return FALSE;
  134.  
  135.       if (fsysdep_in_directory (zfile, zuse, fcheck,
  136.                     freadable, zuser))
  137.         fmatch = TRUE;
  138.     }
  139.  
  140.       ubuffree (zuse);
  141.     }
  142.  
  143.   return fmatch;
  144. }
  145.